<template>
  <div class="box">
    <div :id="id" :style="{height:height,width:width} " />
  </div>
</template>

<script>
import * as echarts from 'echarts'
import {getAwardStatusNumberList} from "../../api/studentAwards";
export default {
  name:'AwardLineChart',
  props: {
    id: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '600px'
    },
    height: {
      type: String,
      default: '400px'
    }
  },
  data() {
    return {
      chart: null,
      echartsData:[
        {
          value:0,
          itemStyle: {
            color: '#5470c6'
          }
        },
        {
          value:0,
          itemStyle: {
            color: '#73c0de'
          }
        },
        {
          value:0,
          itemStyle: {
            color: '#3ba272'
          }
        },
        {
          value:0,
          itemStyle: {
          color: '#9a60b4'
          }
        },
        {
          value:0,
          itemStyle: {
            color: '#fac858'
          }
        },
      ],
    }
  },
  created() {
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
      this.getEchartsData()
    })
  },
  beforeUnmount() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    //得到图表数据
    getEchartsData(){
      getAwardStatusNumberList().then(resopnse => {
        this.echartsData[0].value= resopnse.data[0]
        this.echartsData[1].value= resopnse.data[1]
        this.echartsData[2].value= resopnse.data[2]
        this.echartsData[3].value= resopnse.data[3]
        this.echartsData[4].value= resopnse.data[4]
        console.log(this.echartsData)
        this.chart.setOption({
          series: [
            {
              data: this.echartsData
            }
          ]
        })
      })

    },
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption({
        title: {
          text: '奖项申请数据',
          subtext: '对应人数',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: ['未申请', '已申请', '未答辩', '已答辩', '已出结果']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [
              {
                itemStyle: {
                  color: '#5470c6'
                }
              },
              {
                itemStyle: {
                  color: '#9a60b4'
                }
              },
              {
                itemStyle: {
                  color: '#3ba272'
                }
              },
              {
                itemStyle: {
                  color: '#73c0de'
                }
              },
              {
                itemStyle: {
                  color: '#fac858'
                }
              },
            ],
            type: 'bar'
          }
        ]
      })
    }
  }
}
</script>

<style scoped>
.box {
  padding-top: 40px;
  box-shadow: 0 8px 16px 0 rgb(144, 193, 238);
  /*background-color: #162d7d;*/
  /*background-color: #2c3e50;*/
}
.box:hover {
  /*box-shadow: 0 8px 16px 0 rgb(21, 20, 20);*/
}
</style>
